<template>
    <div>
        <van-nav-bar id="reset" title="每日活动" left-arrow @click-left="backHandle" right-text="积分记录"
            @click-right="toPage('/scoreHistory')" fixed z-index="100" />
        <div class="pageCon fuPage">

            <div class="topBox">
                <span>每日活动</span>
                <span>为什么要做活动 </span>
                <span>为什么要做活动积分是干什么用的 </span>
                <span>积分最终解释去哪</span>
            </div>


            <div class="titleBox">每日活动指引</div>
            <div class="itemMain" v-for="(item, index) in taskList" :key="index">
                <div>
                    <img src="../../assets/score/videoRise.png" alt="" v-if="item.taskId == 2">
                    <img src="../../assets/score/videoShare.png" alt="" v-if="item.taskId == 4">
                    <img src="../../assets/score/videoComm.png" alt="" v-if="item.taskId == 3">
                    <img src="../../assets/score/articleRise.png" alt="" v-if="item.taskId == 5">
                    <img src="../../assets/score/articleComm.png" alt="" v-if="item.taskId == 6">
                    <img src="../../assets/score/articleShare.png" alt="" v-if="item.taskId == 7">
                </div>
                <div>
                    <div>
                        <div>
                            <span>{{ item.taskName }}</span>
                        </div>
                        <span class="c9">任意一篇{{ item.taskName }},可获得{{ user.isVip ? item.vipTaskScore : item.taskScore
                            }}积分</span>
                    </div>
                    <div :class="item.isFinish ? 'finishBtn taskBtn' : 'taskBtn'"
                        @click="toFinish(item.isFinish, item)">
                        {{ item.isFinish ? '已完成' : '去完成' }}
                    </div>
                </div>
            </div>


        </div>
    </div>
</template>

<script>
import { taskList, getUserTask } from '../../network/user'
export default {
    name: 'HomeR',
    data() {
        return {
            taskList: [],//任务列表
            taskStr: '',
            user: JSON.parse(localStorage.user)
        }
    },

    mounted() {

    },
    methods: {

        toPage(url) {
            this.$router.push(url)
        },

        toFinish(flag, obj) {
            console.log(flag);
            console.log(obj);

            if (flag) {
                this.$toast('任务已完成')
            } else {
                var navFlag = obj.taskId == 2 || obj.taskId == 3 || obj.taskId == 4 ? 2 : 3
                this.$router.push({
                    path: '/contentList',
                    query: {
                        flag: navFlag
                    },
                });
            }
        },
        backHandle() {
            this.$router.back()
        },
        getUserTask() {
            getUserTask({
                userId: localStorage.userId
            }).then(res => {
                if (res.flag) {

                    this.taskStr = res.data
                    this.getTaskList()
                }
            })
        },

        getTaskList() {
            taskList().then(res => {
                if (res.flag) {
                    console.log(res);
                    var arr = this.taskStr

                    res.data = res.data.filter(item => {
                        return item.taskName != '阅读'
                    })


                    res.data.forEach(item => {

                        item.isFinish = arr.indexOf(item.taskName) != -1
                    })

                    this.taskList = res.data
                    console.log(this.taskList);
                }

            })
        },




    },
    created() {
        this.getUserTask()
    },
    //计算属性
    computed: {

    },
    filters: {

    }

}

</script>

<style lang='less' scoped>
.pageCon {
    box-sizing: border-box;
    position: relative;
    width: 100%;
    height: 100vh;
    background-color: #EEF1F7;
    // overflow: hidden;
}

.topBox {
    box-sizing: border-box;
    padding: 60px 0 0 34px;
    display: flex;
    flex-direction: column;

    width: 750px;
    height: 324px;
    // background: linear-gradient(-49deg, #78B2F6, #5DCFE6);
    font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 36px;
    color: #FFFFFF;
    background-image: url(../../assets/score/topBg.png);
    background-size: 100% 100%;
}

.topBox>span:not(:first-child) {
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 24px;
    color: #FFFFFF;
    line-height: 36px;
}

.taskBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 136px;
    height: 48px;
    background: linear-gradient(146deg, #14A870, #20BB66);
    box-shadow: 0px 2px 6px 0px rgba(51, 51, 51, 0.16);
    border-radius: 24px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 24px;
    color: #FFFFFF;
}

.finishBtn {
    background: #CCCCCC;
    box-shadow: 0px 2px 6px 0px rgba(51, 51, 51, 0.16);
    border-radius: 24px;
}


#reset /deep/ .van-nav-bar__left .van-nav-bar__text,
#reset /deep/ .van-nav-bar__right .van-nav-bar__text,
#reset /deep/ .van-nav-bar__left .van-icon {
    color: #333 !important;
}

.titleBox {
    margin-bottom: 32px;
    box-sizing: border-box;
    padding-left: 30px;
    width: 100%;
    font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 28px;
    color: #333333;
}


.itemMain {
    display: flex;
    box-sizing: border-box;
    padding: 30px 44px 30px 32px;
    margin: 0 auto 24px;
    width: 690px;
    background: #FFFFFF;
    box-shadow: 0px 2px 6px 0px rgba(51, 51, 51, 0.08);
    border-radius: 20px;
    font-family: Source Han Sans CN;
}

.itemMain>div:first-child {
    display: flex;
    align-items: center;
    justify-content: center;
    // margin-top: 14px;
    margin-right: 30px;
    width: 62px;
    height: 62px;
    background: #F2F2F2;
    border-radius: 20px;
}

.itemMain>div:first-child>img {
    width: 38px;
    height: 38px;
}

.itemMain>div:nth-child(2) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 20px;
    color: #333;
    line-height: 36px;
    // background: aqua;
}

.itemMain>div:nth-child(2)>div>div>span {
    margin-right: 14px;
    font-weight: bold;
    font-size: 28px;
    color: #333333;
}

.c9 {
    color: #858B90;
}

.gre {
    color: #14A870;
}
</style>